<!-----------实名认证页面------------->
<template>
	<div>
		<topheader :toptitle="toptitle"/>
		<div class="wrapper">
			<div class="wrapper-inner">			
				<img class="xy-logo mb0" src="static/img/xy-logo.png"/>
				<div class="go-login realname">
					<p class="realnamebindtip">为落实国家网游实名制，即日起暂停为游客登录用户提供充值服务，建议您用账号登录，尽快完成实名认证。谢谢配合~</p>
					<div class="bind-realname">
						<span class="l-realname">真实姓名</span>
						<input type="text" v-model:value="realname" name="realName" placeholder="请输入您的真实姓名"/>
					</div>
					<div class="bind-ID">
						<span class="l-ID">身份证号</span>
						<input name="xyuserID" type="text" v-model:value="idCard" placeholder="请输入您的身份证号"/>
					</div>					
					<div class="btn btn-normalsize btn-bluebg btn-xyrealname" @click="sureBind">确定</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import Vue from 'vue'
	import topheader from '@/components/topheader'
	import {Toast} from 'mint-ui'
	import apiConfig from '../config/api.js'


	export default {
		name: 'certify',
		components: {
			'topheader':topheader
		},
		data() {
			return {
				toptitle: "实名认证",
				realname:"",
				idCard:""
			}
		},
		created(){

		},
		methods: {
			sureBind: function(){
				if(this.realname === ''){
					this.$Message.warning('请输入您的真实姓名')
					return
				} else if(this.realname !=='' && !/^[\u4E00-\u9FA5]{2,4}$/.test(this.realname)){
					this.$Message.warning('请输入正确的格式')
					return
				}else if(this.idCard === "") {
					this.$Message.warning('请输入您的身份证号')
					return
				}else if(this.idCard !== "" && !/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(this.idCard)) {
					this.$Message.warning('请输入正确的身份证号')
					return
				} else {
					let params = {
			            appid: userInfoKit.appid,
			            token: userInfoKit.getUserInfo().token,
			            real_name:this.realname,
			            mobile: this.userphone,
			            id_card: this.idCard
		        	}
			        // 请求实名认证接口
			        this.$http({
			              method: "GET",
			              url: apiConfig.app.user.realNamecertify,
			              params: params,
			              emulateJSON: true
		            }).then(function (resp) {
			            if (resp.body.code == "200") {
			            	//实名认证成功后调用获取用户信息接口
							let params = {
					            appid: userInfoKit.appid,
					            token: userInfoKit.getUserInfo().token
				        	}
					        // 请求获取用户信息接口
					        this.$http({
					              method: "GET",
					              url: apiConfig.app.user.userInfor,
					              params: params,
					              emulateJSON: true
				            }).then(function (resp) {
					            if (resp.body.code == "200") {
					              //保存用户信息
					              userInfoKit.save(resp.body)
					              //提交成功后跳转到实名认证成功页面
					              //this.$router.push('/certifysuccess');	
					              this.$router.push({ name : "certifysuccess", params: { flag: "show" }});
					            } else {
					              this.$Message.warning(resp.body.msg)
					            }
					        })
			            } else {
			              this.$Message.warning(resp.body.msg)
			            }
			        })
				}
			}
		}
	}
</script>
